<template>
    <div class="app-container" >

        <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
    </div>
</template>

<script>
import {getDevice}from '@/api/device'
export default {
    name:'Aimanage',
    data() {
      return {
        data: [],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      };
    },
    created(){
        this.getList()
    },
    methods: {
        handleNodeClick(data) {
            console.log(data);
        },
        async getList(){
            await getDevice(0)
            .then(res => {
                if(res.data.code==200){
                    this.$message.success("请求成功！")
                    console.log("@@@")
                    // console.log(res.data.data.data)
                    // this.data=res.data.data.data
                    console.log("@@.......@")
                    // console.log(res.data.data.data[0]['deviceId'])
                    // console.log(this.data[0]['deviceId'])
                    //this.data1=res.data.data.data
                    var arr=res.data.data.data
                    for (var i=0;i<arr.length;i++)
                    {
                        var obj = arr[i]
                        var chid=[]
                        for (let key in obj)
                            if (key!='deviceName')
                                chid.push({label:key+":"+obj[key]})
                        console.log(chid)
                        var device={
                            label:'deviceName:'+obj['deviceName'],
                            children:chid
                        }
                        this.data.push(device)
                    }
                    // var chid=[]
                    // for (let key in obj)
                    //     if (key!='deviceName')
                    //         chid.push({label:key+":"+obj[key]})
                    // console.log(chid)
                    // this.data=[{
                    //     label:'deviceName:'+obj['deviceName'],
                    //     children:chid
                    // }]
 

                }
            })
            .catch(error=>{

            })
        }
    }
}
</script>

<style>
@media screen and (min-width:1280px) {
    .container{
        position: relative;
        width:1280px;
    }
}
</style>